package com.hxq.library.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


/**
 * @author jijunxiang
 */
public class JavaDateConnection {
        public Connection getConn() {
            String url = "jdbc:mysql://82.157.145.197/library?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
            String username = "library";
            String password = "asd.123";
            Connection conn = null;
            try {
                Class.forName("com.mysql.cj.jdbc.Driver");
                conn = DriverManager.getConnection(url, username, password);
            } catch (ClassNotFoundException e) {
                System.out.println("连接失败");
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return conn;
        }

        public  static void closeCon(Connection connection) {
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }finally {
                    System.out.println("数据库连接已关闭");
                }
            }

        }

}
